package org.linlinjava.litemall.wx.service;

import jodd.util.CollectionUtil;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.linlinjava.litemall.db.dao.LitemallSeatMapper;
import org.linlinjava.litemall.db.dao.SeatMapper;
import org.linlinjava.litemall.db.dao.StoreMapper;
import org.linlinjava.litemall.db.domain.StoreCategoryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Copyright (C), 2018-2021
 * @Author: JAVA在召唤
 * @Date: 4/13/21 3:20 PM
 * @Description:
 */
@Service
public class WxStoreService {

    @Autowired
    private StoreMapper storeMapper;

    @Autowired
    private LitemallSeatMapper seatMapper;

    @Autowired
    private SeatMapper mySeatMapper;

    @Transactional(readOnly = true)
    public List<StoreCategoryVo> findCategoryVoList(Integer storeId) {
        return storeMapper.selectCategoryVoList(storeId);
    }

    /**
     * 检查订座
     * @param userId
     * @param type
     * @param storeId
     * @param orderTime
     * @param orderRange
     * @return true：可订   false：不可订
     */
    public Integer checkSeat(Integer userId, String type, Integer seatId, Integer storeId, String orderTime, Integer orderRange) {
        Integer minCount = null;
        Integer maxCount = null;

        List<Integer> ids = mySeatMapper.selectAvailableSeat(userId,type,seatId,storeId,orderTime,orderRange);
        if (CollectionUtils.isEmpty(ids)) {
            return 0;
        }
        return ids.get(0);
    }


}
